package com.atguigu.a_collection;

import java.util.ArrayList;
import java.util.Collection;

public class Demo1 {
    public static void main(String[] args) {
        //创建集合对象
        Collection<String> col = new ArrayList<>();
        System.out.println("col = " + col);//[]

        //添加元素
        col.add("张三");
        col.add("李四");
        col.add("王五");
        System.out.println("col = " + col);//["张三","李四","王五"]

        //遍历元素 -> 转数组
        Object[] objs = col.toArray();
        //遍历数组
        for (int i = 0; i < objs.length; i++) {
            //向下转型的前提是 : 真实对象必须是子类型,才能转成相应的子类型
            String name = (String) objs[i];
            System.out.println("name = " + name);
        }
    }
}
